package com.front.teacher.teacherapp.utils;



import android.support.v4.media.MediaBrowserCompat;
import android.util.Base64;
import android.util.Log;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

/**
 * AES加密工具
 */
public class AESUtils {

   // public static final String keyCode = "syztonKey@#$!216";
   public static final String keyCode = "syzton1234567890";
    public static final int CODE_KEY = 0X23;
    // 加密
    public static String Encrypt(String sSrc) {
        try {
            byte[] raw = keyCode.getBytes("utf-8");
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
            byte[] srcbys = sSrc.getBytes("utf-8");
            byte[] encrypted = cipher.doFinal(srcbys);
            String target = new String(  Base64.encode(encrypted,CODE_KEY ));
            System.out.println("on click ");
            return target;//此处使用BASE64做转码功能，同时能起到2次加密的作用。
        } catch (Exception e) {
            System.out.println(e.toString() + "---加密失败");
            return "";
        }

    }
}
